package app.netant.book.dzs5;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Dzs5Detail extends BaseDetail {

	public Dzs5Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.dzs5.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".content.page-book-detail .novel.novel-merge .book-detail-info .book-layout .book-cell #book-detail.book-title");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}	
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".content.page-book-detail .novel.novel-merge .book-detail-info .book-layout .book-cell p.book-meta");
		for(int i=0;i<parts.size();i++){
			if(i==0){
				String writer = parts.get(i).text();
				System.out.println("【Writer】:"+writer);
				this.entity.setNovelWriter(writer);
			}
			else if(i==1){
				String type = parts.get(i).text();
				System.out.println("【Type】:"+type);
				this.entity.setNovelType(type);
			}
			else if(i==2){
				String state = parts.get(i).text();
				System.out.println("【State】:"+state);
				this.entity.setNovelState(state);
			}
			else if(i==3){
				String size = parts.get(i).text();
				System.out.println("【Size】:"+size);
				this.entity.setNovelSize(size);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".content.page-book-detail .novel.novel-merge .book-summary");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".content.page-book-detail .novel ul.btn-group li.btn-group-cell #download-txt.book-fun");
		if(parts.size()>0){
			String refer = parts.get(0).attr("href");
			if(refer.startsWith("/")){
				refer = this.preHref + refer;
			}
			System.out.println("【Refer】:"+refer);
			this.entity.setRefer(refer);
			
			Dzs5Detail detail = new Dzs5Detail(refer);
			String href = detail.stepHref();
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
			
		}
	}
	
	public String stepHref(){
		Elements parts = this.select(".content.page-book-detail .novel ul.btn-group li.btn-group-cell a.book-fun");
		if(parts.size()>0){
			String click = parts.attr("onclick");
			int st = click.indexOf("/download");
			int ed = click.indexOf("');");
			String href = click.substring(st,ed);
			return href;
		}
		return null;
	}
	
	@Override
	public void analyseType() {
		
	}
	
	public static void main(String[] args) {
		Dzs5Detail detail = new Dzs5Detail("https://www.dzs5.com/book/70393.html");
		detail.test();
	}



}
